package com.iotek.bookstore.web.filter;

import com.iotek.bookstore.modle.entity.Book;
import com.iotek.bookstore.modle.entity.TitleOne;
import com.iotek.bookstore.modle.entity.TitleTwo;
import com.iotek.bookstore.modle.service.serviceimpl.BookBizImpl;
import com.iotek.bookstore.modle.service.serviceimpl.TitleOneBizImpl;
import com.iotek.bookstore.modle.service.serviceimpl.TitleTwoBizImpl;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebFilter("/index.jsp")
public class IndexDataInit implements Filter{
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        List<TitleOne> titleOnes=new TitleOneBizImpl().queryAll();
        List<TitleTwo> titleTwos=new TitleTwoBizImpl().queryAll();
        servletRequest.setAttribute("titleOnes",titleOnes);
        servletRequest.setAttribute("titleTwos",titleTwos);
        List<Book>books=new BookBizImpl().queryAll();
        servletRequest.setAttribute("books",books);
        List<Book>timeBooks=new BookBizImpl().query("time");
        servletRequest.setAttribute("timeBooks",timeBooks);
        List<Book>salesBooks=new BookBizImpl().query("sales");
        servletRequest.setAttribute("salesBooks",salesBooks);


        filterChain.doFilter(servletRequest,servletResponse);
    }

    public void destroy() {

    }
}
